/*
 * @Description: 描述信息
 * @Version: 版本号
 * @Author: xuebao
 * @Date: 2023-12-08 16:41:28
 * @LastEditors: renmengxue
 * @LastEditTime: 2023-12-08 16:48:43
 */
import { Store } from 'pinia'
import { ComputedRef, computed } from 'vue'
interface LoadOptions{
  currentPage:ComputedRef<number>
  total:ComputedRef<number>
  pageSize?:number
  [key:string]:any
}
const useLoadMore2 = (store:Store<string, any>, actionName:string, options:LoadOptions) => {
  // Store<string, any> string代表的是store的名称
  const { currentPage, total, pageSize = 5, ...resetOptions } = options

  const requestParams = computed(() => {
    return {
      ...resetOptions,
      currentPage: currentPage.value + 1,
      pageSize
    }
  })
  // 自动调用加载更多方法
  const loadMorePage = () => {
    store[actionName](requestParams.value)
  }
  const isLastPage = computed(() => {
    return Math.ceil(total.value / pageSize) === currentPage.value
  })
  return {
    loadMorePage,
    isLastPage,
    currentPage
  }
}

export default useLoadMore2
